package org.example.threadpool;

import lombok.extern.slf4j.Slf4j;
import org.example.utils.Sleeper;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author zhengdp
 * @Description Timer功能测试
 * @Date 2022/12/20 20:50
 * @Created by zhengdp
 */
@Slf4j(topic = "c.TestTimer")
public class TestTimer {

    public static void main(String[] args) {
        Timer timer = new Timer();
        TimerTask task1 = new TimerTask() {
            @Override
            public void run() {
                log.info("task 1");
                Sleeper.sleep(2000);
            }
        };
        TimerTask task2 = new TimerTask() {
            @Override
            public void run() {
                log.info("task 2");
            }
        };
        log.info("start ...");
        // 延时执行，一秒后执行 task1 和 task2
        timer.schedule(task1,1000);
        timer.schedule(task2,1000);
    }
}
